import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Inject,
  ParseIntPipe,
  ParseUUIDPipe,
  HttpCode,
  Version,
} from '@nestjs/common';
import { UserService } from './user.service';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { Logger } from 'winston';
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
import { User } from '../../core/decorator/user.decorator';
import { Cache } from 'cache-manager';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { MailDto } from './dto/mail.dto';
import { ApiBody, ApiOperation, ApiTags } from "@nestjs/swagger";
@ApiTags('用户测试模块')
@Controller({
  path: 'user',
})
export class UserController {
  constructor(
    private readonly userService: UserService,
    @Inject(WINSTON_MODULE_NEST_PROVIDER)
    private readonly logger: Logger,
    @Inject(CACHE_MANAGER) private cacheManager: Cache,
  ) {}
  @Post()
  @HttpCode(200)
  @ApiOperation({
    summary: '添加用户', // 接口描述信息
  })
  create(@Body() createUserDto: CreateUserDto) {
    return '{dad:dada}';
    // throw new CommonException(40001, '刺配');
    // throw new BadRequestException();
    // console.log('=======createUserDto=====', createUserDto);
    // this.logger.warn(11111111111);
    // return this.userService.create(createUserDto);
    // return 'hello world';
  }

  @Get()
  @Version(['2'])
  async findAll() {
    await this.cacheManager.set('name', 'zhangsan');
    // console.log('======', await this.cacheManager.get('name'));
    return this.userService.findAll();
  }

  @Get(':id')
  findOne(@Param('id', ParseIntPipe) id: string) {
    return this.userService.findOne(+id);
  }

  @Get('u/:uuid')
  async findOne1(@Param('uuid', new ParseUUIDPipe()) uuid: string) {
    return `uuid:${uuid}`;
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
    return this.userService.update(+id, updateUserDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.userService.remove(+id);
  }

  @Get('ubb/b')
  async findUB(@User('firstName') firstName: string) {
    console.log(`Hello ${firstName}`);
    return 1111;
  }

  @Post('ubb')
  async sendEmail(@Body() data: MailDto) {
    return await this.userService.sendResetPasswordEmail(data);
  }
}
